package com.guomao.iodemos;

import java.io.*;

public class DemoA {


    public static void main(String[] args) {

        String filepath = "datatype.dat";


//        writeData(filepath);

        readData(filepath);


    }

    private static void readData(String filepath) {


//        datainputstream DataOutputStream
        try {
            DataInputStream dis = new DataInputStream(new FileInputStream(filepath));

            byte b = dis.readByte();

            char c = dis.readChar();

            long l = dis.readLong();

            float v = dis.readFloat();

            String s = dis.readUTF();

            System.out.println(b);
            System.out.println(c);
            System.out.println(l);
            System.out.println(v);
            System.out.println(s);


        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
        }

    }

    private static void writeData(String filepath) {

        try {
            DataOutputStream dos = new DataOutputStream(new FileOutputStream(filepath));

            dos.writeByte(99);
            dos.writeChar('a');
            dos.writeLong(509L);
            dos.writeFloat(12.35f);

            dos.writeUTF("hello data");

            dos.flush();

        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
        }

    }

}
